package com.scpii.universal.service.impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.InterfaceCateDto;
import com.scpii.universal.dto.InterfaceContDto;
import com.scpii.universal.dto.UserInfoDto;
import com.scpii.universal.hibernate.dao.AppDetailPageDao;
import com.scpii.universal.hibernate.dao.CatelogDao;
import com.scpii.universal.hibernate.dao.ContentDao;
import com.scpii.universal.hibernate.dao.PageModuleConDao;
import com.scpii.universal.hibernate.entity.AppDetailPageTab;
import com.scpii.universal.hibernate.entity.AppPartnerTab;
import com.scpii.universal.hibernate.entity.CatelogTab;
import com.scpii.universal.hibernate.entity.ContentTab;
import com.scpii.universal.hibernate.entity.PageModuleConTab;
import com.scpii.universal.service.CatelogInterface;
import com.scpii.universal.service.CatelogService;

/**
 * 分类接口
 * @author Taylor
 */
@Service
public class CatelogInterfaceImpl extends BaseServiceImpl<CatelogTab, Integer> implements CatelogInterface {
	
	@Resource
	private CatelogDao catelogDao;
	@Resource
	private ContentDao contentDao;
	@Resource
	private AppDetailPageDao appDetailPageDao;
	@Resource
	private PageModuleConDao pageModuleConDao;
	@Resource
	private CatelogService catelogService;
	@Resource
	public void setBaseDao(CatelogDao catelogDao) {
		super.setBaseDao(catelogDao);
	}
	private Log log = LogFactory.getLog(this.getClass());
	private static final String STATUS = "Result";
	private static final String CATEINFOKEY = "CategoryInfo";
	private static final String CONTINFOKEY = "ContentInfo";
	
	/**
	 * 通过URL获取数据
	 * @author Taylor
	 * 2012-10-12 上午09:58:27
	 * @param path
	 * @return
	 * String
	 */
	private String getJsonDataByUrl(String path) {
		try{
			URL url = new URL(path);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			con.setConnectTimeout(30000);
			con.setReadTimeout(30000);
			con.connect();
			InputStream inputStream = con.getInputStream();
			// 对应的字符编码转换
			Reader reader = new InputStreamReader(inputStream, "UTF-8");
			BufferedReader bufferedReader = new BufferedReader(reader);
			String str = null;
			StringBuffer sb = new StringBuffer();
			while ((str = bufferedReader.readLine()) != null) {
				sb.append(str);
			}
			reader.close();
			con.disconnect();
			return sb.toString();
		} catch(IOException e){
			if(e instanceof java.net.ConnectException)
				log.info("通过接口地址获取数据超时", e);
			else
				log.info("通过接口地址获取数据失败", e);
			return "error";
		}
	}
	
	/**
	 * 接口数据操作，保证一个事务
	 * @author Taylor
	 * 2012-10-17 下午05:42:13
	 * @param appPartnerTab
	 * int	0失败，1成功,2接口地址不可用
	 */
	public int save(AppPartnerTab appPartnerTab) {
		int resCate = saveInterfaceCate(appPartnerTab);
		if (resCate != 1)
			return resCate;//更新分类失败，不再去更新内容
		int resCont = saveInterfaceCont(appPartnerTab);
		if (resCont != 1)
			return resCont;
		// 更新时间戳
		updateLastInvokeTime(appPartnerTab.getIntAppPartnerId());
		return 1;
	}
	
	/**
	 * 保存分类,0失败，1成功,2接口地址不可用
	 * @author Taylor
	 * 2012-10-12 下午02:32:31
	 * @param appPartnerTab
	 */
	private int saveInterfaceCate(AppPartnerTab appPartnerTab) {
		String logInfoPre = "应用合作商关联ID:"+appPartnerTab.getIntAppPartnerId()+"----->";
		String lastInvokeTime = "1970-08-21%2011:13:57";
		if (!StringUtils.isBlank(appPartnerTab.getLastInvokeTime())) {
			//非第一次调用该接口，时间戳因为上次调用的时间
			lastInvokeTime = appPartnerTab.getLastInvokeTime().replaceAll(" ", "%20");
		}
		String urlPath = appPartnerTab.getVarInterfaceUrl()+"&Type=0&TimeStamp="+lastInvokeTime;
		log.info(logInfoPre +"调用分类接口开始，请求地址:"+urlPath);
		long timeStart = System.currentTimeMillis();
		//获取数据
		String s = getJsonDataByUrl(urlPath);
		if ("error".equals(s)) {
			log.info(logInfoPre + "接口地址不可用或不能连接到！");
			return 2;
		}
		if(StringUtils.isBlank(s)){
			log.info(logInfoPre +"调用分类接口更新数据结束，没可用数据！");
			return 1;
		}
		long timeGetData = System.currentTimeMillis();
		log.info(logInfoPre +"通过接口地址获取数据花费时间:"+(timeGetData-timeStart)+"ms");
		JSONObject json = JSONObject.fromObject(s);
		String status = json.getString(STATUS);
		if ("0".equals(status.trim())) {
			log.info(logInfoPre+"获取数据返回失败状态！！！调用接口结束");
			return 0;//获取数据失败
		}
        JSONArray arr = JSONArray.fromObject(json.getString(CATEINFOKEY));
        Map<String,InterfaceCateDto> maps = new HashMap<String,InterfaceCateDto>();
        int size = arr.size();
		log.info(logInfoPre +"接口请求到数据条数:" + size + "，数据大小:" + s.getBytes().length + "bytes");
        for (int i = 0; i < size; i++) {
        	JSONObject jo = JSONObject.fromObject(arr.get(i));
        	InterfaceCateDto cate = (InterfaceCateDto) JSONObject.toBean(jo,InterfaceCateDto.class);
        	maps.put(cate.getCatid(), cate);
		}
        //获取数据库中存在的分类
        Map<String,CatelogTab> existCatelogsMap = getCatelogsByAppId(appPartnerTab.getIntAppId());
        Map<String,CatelogTab> updMaps = new HashMap<String,CatelogTab>();
        Iterator<String> it = maps.keySet().iterator();
		int updCount = 0;
		int insertCount = 0;
		StringBuffer updSb = new StringBuffer();
        while (it.hasNext()) {
        	String catid = it.next();
        	InterfaceCateDto cate = maps.get(catid);
			if (existCatelogsMap != null && existCatelogsMap.containsKey(catid)) {
				// 如果数据库中已存在，做更新操作
				updSb.append(catid+",");
				CatelogTab catelog = existCatelogsMap.get(catid);
				catelog.setVarCateName(cate.getCatname());
				catelog.setVarCateImgUrl(cate.getImage());
				catelog.setIntHasSubCate("0".equals(cate.getChild()) ? GenericConstants.IS_HAS_LEAF_NO
						: GenericConstants.IS_HAS_LEAF_YES);
				catelog.setDatUpdateDatetime(new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss").format(new Date()));
				updCount++;
				cate.setIntCateId(catelog.getIntCateId());
			} else {
    			CatelogTab catelogTab = new CatelogTab();
    			populateCatelog(appPartnerTab,cate,catelogTab);
    			catelogTab.setIntHasSubCate("0".equals(cate.getChild()) ? GenericConstants.IS_HAS_LEAF_NO
    							: GenericConstants.IS_HAS_LEAF_YES);
    			int intCateId = catelogDao.save(catelogTab);
    			cate.setIntCateId(intCateId);//和数据库中的intCateId关联
            	updMaps.put(catid, catelogTab);//存入map用于更新parentId
            	insertCount++;
        	}
		}
		if (updCount > 0)
        	log.info(logInfoPre +"更新分类:" + updSb.deleteCharAt(updSb.lastIndexOf(",")).toString());
        
		log.info(logInfoPre +"更新记录条数:" + updCount + "，新增记录条数:" + insertCount);
		UserInfoDto user = new UserInfoDto();
		user.setAppId(appPartnerTab.getIntAppId());
		user.setIntEnterpId(appPartnerTab.getIntEnterpId());
        //更新分类的父分类
        Iterator<String> updIt = updMaps.keySet().iterator();
        while (updIt.hasNext()) {
        	String catid = updIt.next();
        	String parentId = maps.get(catid).getParentid();
        	int parId = 0;
        	int parentHasSubCate = 0;//父分类是否有子节点
        	CatelogTab catelog = updMaps.get(catid);
        	if (existCatelogsMap != null && existCatelogsMap.containsKey(parentId)){
        		//在数据库存在的分类中查找根分类
        		CatelogTab parent = existCatelogsMap.get(parentId);
        		parId = parent.getIntCateId();
        		parentHasSubCate = parent.getIntHasSubCate();
        		catelogDao.updateParentHasSubCate(parId,GenericConstants.IS_HAS_LEAF_YES);//更新父分类是否有子节点
        		catelog.setIntParentCateId(parId);//更新分类父节点
        		//检测父分类是否有引用，有则自动创建页面结构
        		catelogService.saveRelationsByCateId(catelog, catelog.getIntCateId(), parentHasSubCate, user);
        	} else if(maps.containsKey(parentId)){
        		//在请求的数据中查找根分类
        		parId = maps.get(parentId).getIntCateId();
        		catelog.setIntParentCateId(parId);//更新分类父节点
        	} else {
        		catelog.setIntParentCateId(parId);
        	}
        }
        log.info(logInfoPre +"调用分类接口更新数据结束，花费时间:"+(System.currentTimeMillis()-timeGetData)+"ms");
        return 1;
	}
	
	/**
	 * 分类数据封装
	 * @author Taylor
	 * 2012-10-12 上午09:58:10
	 * @param cate
	 * @param catelogTab
	 * void
	 */
	private void populateCatelog(AppPartnerTab appPartnerTab,
			InterfaceCateDto cate, CatelogTab catelogTab) {
		catelogTab.setIntAppId(appPartnerTab.getIntAppId());
		catelogTab.setIntEnterpId(appPartnerTab.getIntEnterpId());

		catelogTab.setVarCateName(cate.getCatname());
		catelogTab.setVarCateImgUrl(cate.getImage());
		catelogTab.setIntSourceId(Integer.parseInt(cate.getCatid()));

		catelogTab.setIntType(1);// 新闻类

		catelogTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
		catelogTab.setDatUpdateDatetime(new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss").format(new Date()));
	}
	
	/**
	 * 根据应用ID查询分类，且intSourceId不为0，即查询出的分类是通过接口存入的
	 * @author Taylor
	 * 2012-10-12 上午09:54:43
	 * @param appId
	 * @return
	 * Map<String,CatelogTab>
	 */
	private Map<String,CatelogTab> getCatelogsByAppId(int appId) {
		StringBuffer hql = new StringBuffer("from CatelogTab c ");
		hql.append("where c.intDeleteSign=:intDeleteSign and c.intSourceId>0 and c.intAppId=:intAppId");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intAppId", appId);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		List<CatelogTab> catelogs =  catelogDao.hqlGetList(hql.toString(), argsMap);
		if (catelogs != null && catelogs.size() > 0) {
			Map<String,CatelogTab> cateMaps = new HashMap<String,CatelogTab>();
			for (CatelogTab catelogTab : catelogs) {
				cateMaps.put(catelogTab.getIntSourceId().toString(), catelogTab);
			}
			return cateMaps;
		} else 
			return null;
	}
	
	/**
	 * 根据应用ID查询内容，且intSourceId不为0，即查询出的内容是通过接口存入的
	 * @author Taylor
	 * 2012-10-12 上午09:54:43
	 * @param appId
	 * @return
	 * Map<String,ContentTab>
	 */
	private Map<String,ContentTab> getContentsByAppId(int appId) {
		StringBuffer hql = new StringBuffer("select new ContentTab(c.intContentId,c.intResourceId) from ContentTab c ");
		hql.append("where c.intDeleteSign=:intDeleteSign and c.intResourceId>0 and c.intAppId=:intAppId");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intAppId", appId);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		List<ContentTab> contents =  contentDao.hqlGetList(hql.toString(), argsMap);
		if (contents != null && contents.size() > 0) {
			Map<String,ContentTab> contMaps = new HashMap<String,ContentTab>();
			for (ContentTab contentTab : contents) {
				contMaps.put(contentTab.getIntResourceId().toString(), contentTab);
			}
			return contMaps;
		} else 
			return null;
	}
	
	/**
	 * 保存内容,0失败，1成功,2接口地址不可用
	 * @author Taylor
	 * 2012-10-12 下午03:01:10
	 * void
	 */
	private int saveInterfaceCont(AppPartnerTab appPartnerTab) {
		String logInfoPre = "应用合作商关联ID:"+appPartnerTab.getIntAppPartnerId()+"----->";
		String lastInvokeTime = "1970-08-21%2011:13:57";
		if (!StringUtils.isBlank(appPartnerTab.getLastInvokeTime())) {
			//非第一次调用该接口，时间戳因为上次调用的时间
			lastInvokeTime = appPartnerTab.getLastInvokeTime().replaceAll(" ", "%20");
		}
		String urlPath = appPartnerTab.getVarInterfaceUrl()+"&Type=1&TimeStamp="+lastInvokeTime;
		log.info(logInfoPre +"调用内容接口开始，请求地址:"+urlPath);
		long timeStart = System.currentTimeMillis();
		//获取数据
		String s = getJsonDataByUrl(urlPath);
		if ("error".equals(s)) {
			log.info(logInfoPre + "接口地址不可用或不能连接到！");
			return 2;
		}
		if(StringUtils.isBlank(s)){
			log.info(logInfoPre +"调用内容接口更新数据结束，没可用数据！");
			return 1;
		}
		long timeGetData = System.currentTimeMillis();
		log.info(logInfoPre +"通过接口地址获取数据花费时间:"+(timeGetData-timeStart)+"ms");
		JSONObject json = JSONObject.fromObject(s);
		String status = json.getString(STATUS);
		if ("0".equals(status.trim())) {
			log.info(logInfoPre+"获取数据返回失败状态或没可用数据！！！调用接口结束");
			return 0;//获取数据失败
		}
        JSONArray arr = JSONArray.fromObject(json.getString(CONTINFOKEY));
        int size = arr.size();
        log.info(logInfoPre +"接口请求到数据条数:" + size + "，数据大小:" + s.getBytes().length + "bytes");
        Map<String,InterfaceContDto> maps = new HashMap<String,InterfaceContDto>();
        for (Object object : arr) {
        	JSONObject jo = JSONObject.fromObject(object);
        	InterfaceContDto cont = (InterfaceContDto) JSONObject.toBean(jo,InterfaceContDto.class);
        	maps.put(cont.getId(), cont);
		}
        contentProcess(maps, appPartnerTab);
        log.info(logInfoPre +"调用内容接口更新数据结束，花费时间:"+(System.currentTimeMillis()-timeGetData)+"ms");
        return 1;
	}
	
	/**
	 * 内容数据处理
	 * @author Taylor
	 * 2012-10-13 下午10:40:12
	 * @param maps
	 * @param appPartnerTab
	 * void
	 */
	private void contentProcess(Map<String,InterfaceContDto> maps,AppPartnerTab appPartnerTab){
		String logInfoPre = "应用合作商关联ID:"+appPartnerTab.getIntAppPartnerId()+"----->";
		int updCount = 0;
		int insertCount = 0;
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		Iterator<String> it = maps.keySet().iterator();
		//获取数据库中存在的内容
		Map<String,ContentTab> existContMaps = getContentsByAppId(appPartnerTab.getIntAppId());
		//存放源分类ID和数据中分类ID的对应
		Map<String,Integer> cateMaps = new HashMap<String,Integer>();
		while (it.hasNext()) {
        	String id = it.next();
        	InterfaceContDto contDto = maps.get(id);
        	String sourceCateId = contDto.getCatid();
        	int intCateId = 0;
        	//根据源分类ID获取数据库中对应的ID
			if (!cateMaps.containsKey(sourceCateId)) {
				intCateId = getCateIdBySourceId(Integer.parseInt(sourceCateId), appPartnerTab.getIntAppId());
				cateMaps.put(sourceCateId, intCateId);
				//如果没有找到对应的分类ID，则将不保存其内容
				if (intCateId == 0){
					log.info(logInfoPre+"注意:源分类ID"+sourceCateId+"在数据库中找不到与之对应的分类，所以该分类下的内容将不会被保存！");
					continue;
				}
				saveAppDetailPage(intCateId, appPartnerTab.getIntAppId());
			} else {
				intCateId = cateMaps.get(sourceCateId);
				if (intCateId == 0)
					continue;
			}
        	
			if (existContMaps != null && existContMaps.containsKey(id)) {
				//更新
				ContentTab exitCont = existContMaps.get(id);
				StringBuffer hql = new StringBuffer("update ContentTab c set");
				hql.append(" c.datUpdateDatetime=:datUpdateDatetime,");
				hql.append(" c.varContentImgUrl=:varContentImgUrl,");
				hql.append(" c.varContentName=:varContentName,");
				hql.append(" c.varContentDescript=:varContentDescript,");
				hql.append(" c.intCateId=:intCateId");
				hql.append(" where c.intContentId=:intContentId");
				Map<String, Object> argsMap = new HashMap<String, Object>();
				argsMap.put("datUpdateDatetime", date);
				argsMap.put("varContentImgUrl", contDto.getThumb());
				argsMap.put("varContentName", contDto.getTitle());
				argsMap.put("varContentDescript",contDto.getContent());
				argsMap.put("intCateId", intCateId);
				argsMap.put("intContentId", exitCont.getIntContentId());
				contentDao.hqlOperation(hql.toString(), argsMap);
				updCount++;
			} else {
				ContentTab content = new ContentTab();
	    		
	    		content.setVarContentName(contDto.getTitle());
	    		content.setVarContentImgUrl(contDto.getThumb());
	    		content.setIntResourceId(Long.parseLong(id));
	    		content.setVarContentDescript(contDto.getContent());
	    		
	    		content.setDatAddDatetime(date);
	    		content.setDatUpdateDatetime(date);
	    		content.setIntCateId(intCateId);
	    		content.setIntEnterpId(appPartnerTab.getIntEnterpId());
	    		content.setIntAppId(appPartnerTab.getIntAppId());
	    		content.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
	    		content.setIntViewCount(0);
	    		content.setIntAction(0);
	    		contentDao.save(content);
	    		insertCount++;
			}
		}
		log.info(logInfoPre+"更新记录条数:" + updCount + "，新增记录条数:" + insertCount);
	}
	
	/**
	 * 根据分类ID获取根分类
	 * @author Taylor
	 * 2012-10-13 下午09:32:39
	 * @param intCateId
	 * @return
	 * CatelogTab
	 */
	private CatelogTab getParentIntCateId(Integer intCateId) {
		// 获取分类列表
		List<CatelogTab> cateList = this.getSuperiorCatelogs(intCateId);
		for (CatelogTab tab : cateList) {
			if (tab.getIntParentCateId() == 0) {
				return tab;
			}
		}
		return null;
	}
	
	private List<CatelogTab> getSuperiorCatelogs(int intCateId){
		StringBuffer sql = new StringBuffer();
		sql.append("select {cate.*} from CATELOG_TAB cate");
		sql.append(" where cate.INT_DELETE_SIGN=0");
		sql.append(" start with cate.INT_CATE_ID=:intCateId");
		sql.append(" connect by prior cate.INT_PARENT_CATE_ID=cate.INT_CATE_ID");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intCateId",intCateId);
		return catelogDao.findBySql(sql.toString(), argsMap);
	}
	
	/**
	 * 根据源分类ID获取数据库中对应的ID
	 * @author Taylor
	 * 2012-10-13 下午10:16:33
	 * @param sourceId
	 * @param appId
	 * @return
	 * int
	 */
	private int getCateIdBySourceId(int sourceId,int appId) {
		StringBuffer hql = new StringBuffer("select new CatelogTab(c.intCateId, c.varCateName) from CatelogTab c");
		hql.append(" where c.intDeleteSign=:intDeleteSign and c.intSourceId=:sourceId and c.intAppId=:intAppId");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intAppId", appId);
		argsMap.put("sourceId", sourceId);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		List<CatelogTab> catelogs =  catelogDao.hqlGetList(hql.toString(), argsMap);
		if (catelogs != null && catelogs.size() > 0) {
			return catelogs.get(0).getIntCateId();
		} else 
			return 0;
	}
	
	/**
	 * 保存详情页模块，否则不能查询详情
	 * @author Taylor
	 * 2012-10-13 下午10:26:31
	 * @param intCateId
	 * @param appId
	 * void
	 */
	private void saveAppDetailPage(int intCateId, int appId) {
		//获取最终根分类
		CatelogTab parentCate = this.getParentIntCateId(intCateId);
		if (parentCate == null) {
			log.info("未找到分类" + intCateId + "的最终根分类");
			return;
		}
		// 判断根节点是否存在详情页面记录
		boolean flag = checkIfAppDetailPageExist(parentCate.getIntCateId());
		//应用详情页面表
		if (!flag) {
			String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
			AppDetailPageTab pageTab = new AppDetailPageTab();
			pageTab.setIntAppId(appId);
			pageTab.setIntDetailPageCateid(parentCate.getIntCateId());
			pageTab.setVarPageDetailName(parentCate.getVarCateName());
			pageTab.setIntPageDetailType(parentCate.getIntType());
			pageTab.setVarPageUrl("universalWeb/dataBinding/goContentDetail.action?intContentId=");
			pageTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
			pageTab.setDatUpdateDatetime(date);
			appDetailPageDao.save(pageTab);
			// 保存页面显示循序和内容
			for (int i = 0; i < 6; i++) {
				PageModuleConTab conTab = new PageModuleConTab();
				// 应用详情页面ID
				conTab.setIntPageDetailId(pageTab.getIntPageDetailId());
				conTab.setIntPageModuleId(i + 1);
				conTab.setIntPageModuleOrder((byte) (i + 1));
				conTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
				conTab.setDatUpdateDatetime(date);
				pageModuleConDao.save(conTab);
			}
		}
	}
	
	/**
	 * 判断根节点是否存在详情页面记录
	 * @author Taylor
	 * 2012-10-15 上午11:41:51
	 * @param cateId
	 * @return
	 * boolean
	 */
	private boolean checkIfAppDetailPageExist(int cateId){
		StringBuffer hql = new StringBuffer("select new AppDetailPageTab(intPageDetailId) from AppDetailPageTab a");
		hql.append(" where a.intDeleteSign=:intDeleteSign and a.intDetailPageCateid=:intDetailPageCateid");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intDetailPageCateid", cateId);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		List<AppDetailPageTab> details =  appDetailPageDao.hqlGetList(hql.toString(), argsMap);
		if (details != null && details.size() > 0) {
			return true;
		} else 
			return false;
	}
	
	/**
	 * 更新接口最后调用时间
	 * @author Taylor
	 * 2012-10-17 下午04:59:08
	 * void
	 */
	private void updateLastInvokeTime(int intAppPartnerId){
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		StringBuffer hql = new StringBuffer("update AppPartnerTab a set");
		hql.append(" a.datUpdateDatetime=:datUpdateDatetime,");
		hql.append(" a.lastInvokeTime=:lastInvokeTime");
		hql.append(" where a.intAppPartnerId=:intAppPartnerId");
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("datUpdateDatetime", date);
		argsMap.put("lastInvokeTime",date);
		argsMap.put("intAppPartnerId", intAppPartnerId);
		contentDao.hqlOperation(hql.toString(), argsMap);
	}
}
